//
//  MessageViewController.m
//  Youhuiju
//
//  Created by yutenys on 16/7/29.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "MessageViewController.h"
//跳转界面
#import "MessageDetailViewController.h"
//自定义视图
#import "MessageTopView.h"//顶上视图

#import "MessageTableViewCell.h"//tableViewCell

@interface MessageViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)MessageTopView *topView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation MessageViewController

static NSString *MessageTableViewCellIden  = @"MessageTableViewCellIden";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self load_UI];
    
    // Do any additional setup after loading the view from its nib.
    
    
}

#pragma mark ------- load_UI
-(void)load_UI
{
    [self topView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:nil] forCellReuseIdentifier:MessageTableViewCellIden];

    self.automaticallyAdjustsScrollViewInsets = NO;

    
}

#pragma mark ---------- tableView delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 61 * FitH;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MessageTableViewCellIden forIndexPath:indexPath];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DLog(@"~~~~~~~~~~~~~~~~~~~");
    MessageDetailViewController *mvc = [[MessageDetailViewController alloc]initWithNibName:@"MessageDetailViewController" bundle:nil];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:mvc animated:YES];
};



-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -------lazy loading
-(MessageTopView *)topView
{
    WeakObj(self);
    if (!_topView)
    {
        _topView = [[MessageTopView alloc]init];
        _topView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_topView];
        
        _topView.backButtonClickedHandler = ^{
            
            [weakself.navigationController popViewControllerAnimated:YES];
        };
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.top.equalTo(self.view.mas_top).offset(20);
            make.right.equalTo(self.view.mas_right);
            make.height.mas_offset(44);
        }];
    }
    return _topView;
}


@end
